# -*- coding: utf-8 -*-
from venv1.Page.policyIfmComPage import policyIfmComPage
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import xlrd
class UWdeal():
    def __init__(self,driver):
        self.driver=driver
        self.policyIfmComPage=policyIfmComPage(self.driver)
    def UWdeal(self,PolicyNo,UWidea):
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)
        self.policyIfmComPage.btnUWfllowup().click()
        time.sleep(1)
        self.policyIfmComPage.inpPolicyNo().send_keys(PolicyNo)
        time.sleep(1)
        self.policyIfmComPage.btnPolicyGet().click()
        time.sleep(1)
        # 切換窗口
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)
        # 點擊彈框確認按鈕
        self.policyIfmComPage.btnSubmit().click()
        time.sleep(1)
        try:
            # 切換窗口
            window1 = self.driver.window_handles
            self.driver.switch_to.window(window1[-1])
            time.sleep(10)
            # 選擇目標數據
            self.policyIfmComPage.TargetData().click()
            time.sleep(2)
            window2 = self.driver.window_handles
            self.driver.switch_to.window(window2[-1])
            time.sleep(5)

            ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('W').key_up(Keys.CONTROL).perform()
            time.sleep(1)
            # self.policyIfmComPage.btninsured().click()
            # time.sleep(1)
            # self.policyIfmComPage.btnSubmit1().click()
            # time.sleep(1)
            # self.policyIfmComPage.btnSubmit().click()
            # time.sleep(1)
            # 输入拒保意见
            self.policyIfmComPage.inpUWidea().send_keys(UWidea)
            time.sleep(1)
            # 点击拒保
            self.policyIfmComPage.btnDrop().click()
            time.sleep(1)
            # 点击确认
            self.policyIfmComPage.btnSubmit1().click()
            time.sleep(1)
            # 点击确认
            # self.policyIfmComPage.btnSubmit().click()
            # time.sleep(1)
            # window4 = self.driver.window_handles
            # self.driver.switch_to.window(window4[-1])
            # time.sleep(1)
            self.policyIfmComPage.inpDropreson().click()
            time.sleep(1)
            filename = r'..\\data\\testdata.xlsx'
            excel_open = xlrd.open_workbook(filename)
            table = excel_open.sheet_by_name('Sheet1')
            rows = table.nrows
            for i in range(2, rows):
                row_content = table.row_values(i)
                Dropreson = row_content[80]
                OtherDropreson=row_content[81]
                if Dropreson =='健康原因':
                    self.policyIfmComPage.btnHealth().click()
                    time.sleep(1)
                elif Dropreson=='财务原因':
                    self.policyIfmComPage.btnFinancial().click()
                    time.sleep(1)
                elif Dropreson=='职业原因':
                    self.policyIfmComPage.btnProfessional().click()
                    time.sleep(1)
                elif Dropreson=='高风险国家和地区原因':
                    self.policyIfmComPage.btnRisk().click()
                    time.sleep(1)
                else:
                    self.policyIfmComPage.btnOther().click()
                    time.sleep(1)
                    self.policyIfmComPage.inpDropreson().send_keys(OtherDropreson)
                    time.sleep(1)
                self.policyIfmComPage.btnSumbit4().click()
                time.sleep(1)
                self.policyIfmComPage.btnSubmit2().click()
                time.sleep(1)












        except Exception as msg:
            print('error:',msg)